#ifndef _SDM_H_
#define _SDM_H_

#include <vec.h>

extern class Polygon;
extern class AABB;

typedef struct  
{
	Vec2d p;
	Vec2d n;
	double d;
} Value;

class SDM
{
public:
	SDM(void);
	~SDM(void);

	virtual Value getEvaluation(Vec2d p, bool compute_normal) = 0;
};

class BruteForceSDM : public SDM
{
public:
	BruteForceSDM(void);
	BruteForceSDM(Polygon* p);
	~BruteForceSDM(void);

	Value getEvaluation(Vec2d p, bool compute_normal);

	Polygon* poly;
};

class GridSDM : public SDM
{
public:
	GridSDM(void);
	~GridSDM(void);
	GridSDM(Polygon* poly, double cellSize);

	double getGridData(int x, int y);
	void setGridData(int x, int y, double v);
	bool getGridInitData(int x, int y);
	void setGridInitData(int x, int y, bool v);
	double getGridValue(int x, int y);

	Value getEvaluation(Vec2d p, bool compute_normal);

	double* grid;
	bool* gridInitialized;
	AABB* bbox;
	double cellSize;
	double invCellSize;
	BruteForceSDM* bfsdm;

	int w, h;
};

#endif



